package com.wzdigit.wms.raw.webservice;


import com.wzdigit.framework.exception.RestStatusException;
import com.wzdigit.wms.basic.domain.dtos.api.ApiMessage;
import com.wzdigit.wms.basic.domain.dtos.api.ApiSapMessage;
import com.wzdigit.wms.raw.domain.dto.CancelGdnDto;
import com.wzdigit.wms.raw.service.gdn.GdnDtlCancelService;
import com.wzdigit.wms.raw.webservice.impl.SapCancelGdnDtlWebService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.jws.WebService;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
@Component
@WebService(targetNamespace="http://impl.webservice.raw.wms.wzdigit.com",
        endpointInterface = "com.wzdigit.wms.raw.webservice.impl.SapCancelGdnDtlWebService")
public class SapCancelGdnDtlWebServiceImpl implements SapCancelGdnDtlWebService {


    @Autowired
    GdnDtlCancelService gdnDtlCancelService;


    @Override
    public ApiSapMessage cancelSapGdnDtl(CancelGdnDto cancelGdnDto) {
        System.out.println("调用取消单据接口==>"+cancelGdnDto);

        HttpServletRequest request =((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpServletResponse response =((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getResponse();
        try {
            //return    gdnDtlCancelService.cancelDtlGdn(cancelGdnDto.getGdnNo(),cancelGdnDto.getLineNo(),request,response);
            return    gdnDtlCancelService.cancelDtlGdn(cancelGdnDto.getGdnNo(),cancelGdnDto.getLineNo(),cancelGdnDto.getType(),request,response);
        }catch (RestStatusException e){
            return  new ApiSapMessage(ApiSapMessage.STATUS_NO,e.getContent());
        } catch (Exception e) {
            log.info(e.getMessage());
            return  new ApiSapMessage(ApiSapMessage.STATUS_NO,"系统错误，未知异常");
        }




    }
}
